package com.yuelao.thread.demo;

import java.util.concurrent.CountDownLatch;

/**
 * 线程等待测试
 * Created by fengliye on 2017/10/7.
 */
public class CountDownLatchTest {
    // 需要等待执行完的节点数
    static CountDownLatch c = new CountDownLatch(2);

    public static void main(String[] args) {
        new Thread(() ->{
            c.countDown();
            System.out.println("t1...finish");
        }, "t1").start();

        new Thread(() ->{
            try {
                Thread.sleep(5000l);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            c.countDown();
            System.out.println("t2...finish");
        }, "t2").start();
        try {
            c.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("main...finish");
    }


}
